package com.yxuan.springboot.controller;

import com.yxuan.springboot.model.OneParaRange;
import com.yxuan.springboot.service.OneParagraphService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheConfig;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.stereotype.Controller;
import com.yxuan.springboot.model.OneParagraph;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author zchao
 *   OneParagraph控制器
 * @date 2023-05-17 17:19:09
 */
@Controller
@Api(tags = "一分一段表")
@RequestMapping(value = "/oneparagraph", method = {RequestMethod.POST,RequestMethod.GET})
@CacheConfig(cacheNames = "oneparagraph")//缓存名，和管理器中配置的一致
public class OneParagraphController extends BaseController<OneParagraph>{

    @Autowired
    private OneParagraphService oneParagraphService;

    /**
     *  传入省份和年份，搜索该对应的类型
     */
    @ApiOperation(value = "查询一分一段类型", notes = "查询一分一段类型")
    @RequestMapping("/loadClassificationGroup")
    @ResponseBody
    @Cacheable(key = "'ClassificationGroup-' + #province + #year",unless = "#result==null", condition = "#province!=null && #year != null")//#result返回结
    public ArrayList loadClassificationGroup(String province,String year){
        Map<String,Object> map = new HashMap<>();
        List<OneParagraph> OneList = oneParagraphService.findClassificationGroup(province,year);
        ArrayList arrayList = new ArrayList();
        for (OneParagraph oneParagraph : OneList){
            arrayList.add(oneParagraph.getClassification());
        }
        return arrayList;
    }

    /**
     *  查询历年等位分
     */
    @ApiOperation(value = "查询历年等位分", notes = "查询历年等位分")
    @RequestMapping("/loadHistorySame")
    @ResponseBody
    public List<OneParagraph> loadHistorySame(String score, String province, String classification, String year){
        List<OneParagraph> list = oneParagraphService.findHistorySame(score,province,classification,year);
        System.out.println(list);
        return list;
    }



    /**
     *  查询区间分数以及人数
     */
    @ApiOperation(value = "查询区间分数以及人数", notes = "查询区间分数以及人数")
    @RequestMapping("/loadRangeNumber")
    @ResponseBody
    @Cacheable(key = "'loadRangeNumber-' + #province + #year +#classification",unless = "#result==null", condition = "#province!=null && #year != null && #classification!=null")//#result返回结
    public List<OneParaRange> loadRangeNumber(String province, String year, String classification){
        List<OneParaRange> list = oneParagraphService.findRangeNumber(province,year,classification);
        System.out.println(list);
        return list;
    }

}
